package com.itheima.demo03;

public class Ticket implements Runnable{
    private int tickets = 100;
    private Object lock = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (lock) {
                if (tickets <= 0) {
                    break;
                }else {
                    tickets--;
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "正在买票，还剩" + tickets + "张票！");
                }
            }
        }
    }
}
